﻿#region File Description
//-----------------------------------------------------------------------------
// ParticleSettings.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace The_LarX
{
    /// <summary>
    /// Settings class describes all the tweakable options used
    /// to control the appearance of a particle system.
    /// </summary>
    public class ParticleSettings
    {
        // Name of the texture used by this particle system.
        public string TextureName = null;


        // Maximum number of particles that can be displayed at one time.
        public int MaxParticles = 100;


        // How long these particles will last.
        public float Duration = 1;


        // If greater than zero, some particles will last a shorter time than others.
        public float DurationRandomness = 0;


        // Controls how much particles are influenced by the velocity of the object
        // which created them. You can see this in action with the explosion effect,
        // where the flames continue to move in the same direction as the source
        // projectile. The projectile trail particles, on the other hand, set this
        // value very low so they are less affected by the velocity of the projectile.
        public float EmitterVelocitySensitivity = 1;


        // Range of values controlling how much X and Z axis velocity to give each
        // particle. Values for individual particles are randomly chosen from somewhere
        // between these limits.
        public float MinHorizontalVelocity = 0;
        public float MaxHorizontalVelocity = 0;


        // Range of values controlling how much Y axis velocity to give each particle.
        // Values for individual particles are randomly chosen from somewhere between
        // these limits.
        public float MinVerticalVelocity = 0;
        public float MaxVerticalVelocity = 0;


        // Direction and strength of the gravity effect. Note that this can point in any
        // direction, not just down! The fire effect points it upward to make the flames
        // rise, and the smoke plume points it sideways to simulate wind.
        public Vector3 Gravity = Vector3.Zero;


        // Controls how the particle velocity will change over their lifetime. If set
        // to 1, particles will keep going at the same speed as when they were created.
        // If set to 0, particles will come to a complete stop right before they die.
        // Values greater than 1 make the particles speed up over time.
        public float EndVelocity = 1;


        // Range of values controlling the particle color and alpha. Values for
        // individual particles are randomly chosen from somewhere between these limits.
        public Color MinColor = Color.White;
        public Color MaxColor = Color.White;


        // Range of values controlling how fast the particles rotate. Values for
        // individual particles are randomly chosen from somewhere between these
        // limits. If both these values are set to 0, the particle system will
        // automatically switch to an alternative shader technique that does not
        // support rotation, and thus requires significantly less GPU power. This
        // means if you don't need the rotation effect, you may get a performance
        // boost from leaving these values at 0.
        public float MinRotateSpeed = 0;
        public float MaxRotateSpeed = 0;


        // Range of values controlling how big the particles are when first created.
        // Values for individual particles are randomly chosen from somewhere between
        // these limits.
        public float MinStartSize = 100;
        public float MaxStartSize = 100;


        // Range of values controlling how big particles become at the end of their
        // life. Values for individual particles are randomly chosen from somewhere
        // between these limits.
        public float MinEndSize = 100;
        public float MaxEndSize = 100;
        
        // Alpha blending settings.
        private BlendState blendState = BlendState.NonPremultiplied;
        public BlendState BlendState
        {
            get { return blendState; }
            set { blendState = value; }
        }

        public virtual void SerializeData(SerializeData Data)
        {
            Data.AddData("ParticleSettings.ParticleTexture", this.TextureName);
            Data.AddData("ParticleSettings.MaxParticles", this.MaxParticles);
            Data.AddData("ParticleSettings.Duration", this.Duration);
            Data.AddData("ParticleSettings.DurationRandomness", this.DurationRandomness);
            Data.AddData("ParticleSettings.EmitterVelocitySensitivity", this.EmitterVelocitySensitivity);
            Data.AddData("ParticleSettings.MinHorizontalVelocity", this.MinHorizontalVelocity);
            Data.AddData("ParticleSettings.MaxHorizontalVelocity", this.MaxHorizontalVelocity);
            Data.AddData("ParticleSettings.MinVerticalVelocity", this.MinVerticalVelocity);
            Data.AddData("ParticleSettings.MaxVerticalVelocity", this.MaxVerticalVelocity);
            Data.AddData("ParticleSettings.Gravity", this.Gravity);
            Data.AddData("ParticleSettings.MinColor", this.MinColor);
            Data.AddData("ParticleSettings.MaxColor", this.MaxColor);
            Data.AddData("ParticleSettings.MinRotateSpeed", this.MinRotateSpeed);
            Data.AddData("ParticleSettings.MaxRotateSpeed", this.MaxRotateSpeed);
            Data.AddData("ParticleSettings.MinStartSize", this.MinStartSize);
            Data.AddData("ParticleSettings.MaxStartSize", this.MaxStartSize);
            Data.AddData("ParticleSettings.MinEndSize", this.MinEndSize);
            Data.AddData("ParticleSettings.MaxEndSize", this.MaxEndSize);
        }
        public bool Deserialized;
        public virtual void DeserializeData(SerializeData Data)
        {
            Deserialized = true;
            this.TextureName = Data.GetData<string>("ParticleSettings.ParticleTexture");
            this.MaxParticles = Data.GetData<int>("ParticleSettings.MaxParticles");
            this.Duration = Data.GetData<float>("ParticleSettings.Duration");
            this.DurationRandomness = Data.GetData<float>("ParticleSettings.DurationRandomness");
            this.EmitterVelocitySensitivity = Data.GetData<float>("ParticleSettings.EmitterVelocitySensitivity");
            this.MinHorizontalVelocity = Data.GetData<float>("ParticleSettings.MinHorizontalVelocity");
            this.MaxHorizontalVelocity = Data.GetData<float>("ParticleSettings.MaxHorizontalVelocity");
            this.MinVerticalVelocity = Data.GetData<float>("ParticleSettings.MinVerticalVelocity");
            this.MaxVerticalVelocity = Data.GetData<float>("ParticleSettings.MaxVerticalVelocity");
            this.Gravity = Data.GetData<Vector3>("ParticleSettings.Gravity");
            this.MinColor = Data.GetData<Color>("ParticleSettings.MinColor");
            this.MaxColor = Data.GetData<Color>("ParticleSettings.MaxColor");
            this.MinRotateSpeed = Data.GetData<float>("ParticleSettings.MinRotateSpeed");
            this.MaxRotateSpeed = Data.GetData<float>("ParticleSettings.MaxRotateSpeed");
            this.MinStartSize = Data.GetData<float>("ParticleSettings.MinStartSize");
            this.MaxStartSize = Data.GetData<float>("ParticleSettings.MaxStartSize");
            this.MinEndSize = Data.GetData<float>("ParticleSettings.MinEndSize");
            this.MaxEndSize = Data.GetData<float>("ParticleSettings.MaxEndSize");            
        }
    }
}
